package com.training.oo.object;

public class Carx implements Cloneable{
	private String regNum;
	private String brand;
	private double price;
	public String getRegNum() {
		return regNum;
	}
	public void setRegNum(String regNum) {
		this.regNum = regNum;
	}
	public String getBrand() {
		return brand;
	}
	public void setBrand(String brand) {
		this.brand = brand;
	}
	public double getPrice() {
		return price;
	}
	public void setPrice(double price) {
		this.price = price;
	}
	
	@Override
	protected void finalize() throws Throwable {
		System.out.println("我即将被回收...");
	}
	
//	//重写他们的hashcode和equals方法使得他们的hashcode不同
//	@Override
//	public int hashCode() {
//		final int prime = 31;
//		int result = 1;
//		result = prime * result + ((brand == null) ? 0 : brand.hashCode());
//		long temp;
//		temp = Double.doubleToLongBits(price);
//		result = prime * result + (int) (temp ^ (temp >>> 32));
//		result = prime * result + ((regNum == null) ? 0 : regNum.hashCode());
//		return result;
//	}
//	@Override
//	public boolean equals(Object obj) {
//		if (this == obj)
//			return true;
//		if (obj == null)
//			return false;
//		if (getClass() != obj.getClass())
//			return false;
//		Carx other = (Carx) obj;
//		if (brand == null) {
//			if (other.brand != null)
//				return false;
//		} else if (!brand.equals(other.brand))
//			return false;
//		if (Double.doubleToLongBits(price) != Double.doubleToLongBits(other.price))
//			return false;
//		if (regNum == null) {
//			if (other.regNum != null)
//				return false;
//		} else if (!regNum.equals(other.regNum))
//			return false;
//		return true;
//	}
	@Override
	public String toString() {
		return "Carx [regNum=" + regNum + ", brand=" + brand + ", price=" + price + "]";
	}
	
	@Override
	protected Object clone() throws CloneNotSupportedException {
		// TODO Auto-generated method stub
		return super.clone();
	}
	
	public static void main(String[] args) throws Exception {
//		Carx x1 = new Carx();
//		System.out.println(x1.hashCode());
//		
//		Carx x2 = new Carx();
//		System.out.println(x2.hashCode());
//		
//		System.out.println(x2==x1);
//		System.out.println(x2.equals(x1));// ==
//		
//		System.out.println("----------------------------------");
//		String s1 = new String("abc");
//		String s2 = new String("abc");
//		System.out.println(s1==s2);
//		System.out.println(s1.equals(s2));
		
		Carx xx = new Carx();
		
		xx.setBrand("BMW");
		xx.setPrice(11111111);
		xx.setRegNum("陕A13215");
		
		Carx y = (Carx) xx.clone();
		System.out.println(y);
//		System.out.println(xx);
//		xx = null;
//		System.gc();
	}
	
}
